package com.zhangpeng520.common.security;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.util.Base64;


public class SecurityUtils {

    /**
     * @Author zhangpeng(www.zhangpeng520.com)
     * @Date 2017/8/9 0009 16:00
     * @Desripition 用加密函数对用户密码加密
     */
    public  static String encryptPassword(String password) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64Encoder = new BASE64Encoder();
        String securitypassword = base64Encoder.encode(md5.digest(password.getBytes("UTF-8")));

        return securitypassword;
    }

    /**
     * @Author zhangpeng(www.zhangpeng520.com)
     * @Date 2017/8/9 0009 16:00
     * @Desripition 验证密码是否与数据密码一致
     */
    public static boolean checkpassword(String password, String securitypassword) throws Exception {

        String encryptpassword = encryptPassword(password);

        if (encryptpassword.equals(securitypassword)) {
            return true;
        } else {
            return false;
        }

    }
}


